part of 'chooser.dart';

class BottomSheetChooser {
  static showBottomSheetChooser({
    required BuildContext context,
    bool showTitleView = true,
    Function? onCancel,
    Function(dynamic)? onConfirm,
    String? title,
    String cancel = '取消',
    String confirm = '确定',
    TextStyle cancelTextStyle = const TextStyle(fontSize: 14, color: Colors.grey),
    TextStyle confirmTextStyle = const TextStyle(fontSize: 14, color: Colors.blue),
    TextStyle titleTextStyle = const TextStyle(fontSize: 16, color: Colors.black),
    TextStyle? selectTextStyle = const TextStyle(fontSize: 16, color: Colors.black),
    TextStyle? unSelectTextStyle =const TextStyle(fontSize: 16, color: Colors.grey),
    Function(dynamic)? onValueChanged,
    required List<dynamic> datas,
    int startPosition = 0,
  }) {
   return showModalBottomSheet(
        context: context,
        builder: (context) {
          dynamic data;
          if (!ObjectUtil.isEmptyList(datas)) {
            data = datas[0];
          }
          return Container(
            width: double.infinity,
            height: 300.0,
            child: Column(
              children: [
                Visibility(
                  visible: showTitleView,
                  child: Container(
                    decoration: BoxDecoration(border: Border(bottom: BorderSide(color: Colors.grey.withOpacity(0.3), width: 0.5))),
                    child: Row(
                      children: [
                        InkWell(
                            onTap: () => Navigator.of(context).pop(),
                            child: Padding(
                              padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
                              child: Text(
                                cancel,
                                style: cancelTextStyle,
                              ),
                            )),
                        Expanded(
                            child: Center(
                              child: Text(
                                title ?? '',
                                style: titleTextStyle,
                              ),
                            )),
                        InkWell(
                            onTap: () {
                              onConfirm?.call(data);
                              Navigator.of(context).pop(data);
                            },
                            child: Padding(
                              padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
                              child: Text(
                                confirm,
                                style: confirmTextStyle,
                              ),
                            )),
                      ],
                    ),
                  ),
                ),
                Expanded(
                    child: WheelChooser(
                      onValueChanged: (value) {
                        data = value;
                        onValueChanged?.call(value);
                      },
                      datas: datas,
                      selectTextStyle: selectTextStyle,
                      unSelectTextStyle: unSelectTextStyle,
                      startPosition: startPosition,
                    )),
              ],
            ),
          );
        });
  }
}
